package daobeauty.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
 * Created 16.09.2008
 * @author M. Serhat Cinar
 *
 */
public final class StringUtils {
	
	private StringUtils(){}
	
	public static String toString(Map args){
		if (args==null){
			return "null";
		}
		final StringBuilder sb = new StringBuilder(128);
		sb.append("{Map["+args.size()+"]:");
		final Iterator iter = args.keySet().iterator();
		Object key;
		while (iter.hasNext()){
			key = iter.next();
			sb.append(String.valueOf(key)+"="+String.valueOf(args.get(key)));
			if (iter.hasNext()){
				sb.append(", ");
			}
		}
		sb.append("}");
		return sb.toString();
	}
	
	@SuppressWarnings("unchecked")
	public static String toString(Collection col){
		if (col==null){
			return "null";
		}
		return toString(col.toArray(new Object[col.size()]));
	}
	
	public static String toString(Object [] args){
		if (args==null){
			return "null";
		}
		final StringBuilder sb = new StringBuilder(128);
		sb.append("{Array["+args.length+"]:");
		for (int i=0; i<args.length; i++){
			if (i!=0){
				sb.append(", ");
			}
			if (args[i]==null){
				sb.append("null");
			}
			else if (args[i].getClass().isArray()){
				sb.append(toString((Object []) args[i]));
			}
			else{
				sb.append(String.valueOf(args[i]));
			}
		}
		sb.append("}");
		return sb.toString();
	}
}
